import { ref } from "vue";
import { utils, writeFile } from "xlsx";
import { getPage_BeingContractList } from "@/api/baseUrApi";
import data from "@iconify-icons/ep/home-filled";
import { message } from "@/utils/message";
let dataList: any[] = [];
await getPage_BeingContractList({ page: 1, size: 20 }).then(res => {
  dataList = res.data;
});
export function useColumns() {
  const columns: TableColumnList = [
    {
      label: "编号",
      prop: "Sign_userid"
    },
    {
      label: "签约人姓名",
      prop: "Contractor_name"
    },
    {
      label: "身份证号",
      prop: "Contractor_id"
    },
    {
      label: "手机号码",
      prop: "Contractor_phone"
    },
    {
      label: "签约状态",
      prop: "Sign_state"
    },
    {
      label: "签约医生团队",
      prop: "Sign_doctor"
    },
    {
      label: "签约服务包",
      prop: "Pack_type"
    },
    {
      label: "最后修改时间",
      prop: "Sign_Atime"
    },
    {
      label: "操作",
      cellRenderer: ({ index, row }) => (
        <>
          <el-button size="small"  type="primary" onClick={() =>window.location.href="http://localhost:8848/editcontract#/contractmanage/editcontract"}>
            详情
          </el-button>
          <el-button
            size="small"
            type="primary"
            onClick={() =>window.location.href="http://localhost:8848/editcontract#/contractmanage/disposecontract"}  
          >
            编辑
          </el-button>
        </>
      )
    }
  ];
  const exportExcel = () => {
    const res = dataList.map(item => {
       console.log(dataList,"d1")
      const arr = [];
      columns.forEach(column => {
        arr.push(item[column.prop as string]);
      });
      return arr;
    });
    const titleList = [];
    columns.forEach(column => {
      titleList.push(column.label);
    });
    res.unshift(titleList);
    const workSheet = utils.aoa_to_sheet(res);
    //导出数据
    const workBook = utils.book_new();
    utils.book_append_sheet(workBook, workSheet, "数据报表");
    writeFile(workBook, "pure-admin-table.xlsx"); //数据名称
    message("导出成功", {
      type: "success"
    });
  };

  return {
    columns,
    dataList,
    exportExcel
  };
}
